package leetcode.code0135;

public class Solution extends Solution135 {

	@Override
	public int candy(int[] ratings) {
		int len = ratings.length;
		int[] candy = new int[len];
		candy[0] = 1;
		for (int i = 1; i < len; i++) {
			candy[i] = ratings[i] > ratings[i - 1] ? candy[i - 1] + 1 : 1;
		}
		int ans = candy[len - 1];
		for (int i = len - 2; i >= 0; i--) {
			candy[i] = ratings[i] > ratings[i + 1] ? candy[i] > candy[i + 1] ? candy[i] : candy[i + 1] + 1 : candy[i];
			ans += candy[i];
		}
		return ans;
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
	}

}
